package org.groupg.filetodb.model.finals;

import org.groupg.filetodb.model.TaskRunning;

import java.time.LocalDateTime;

public enum TaskRunningStatus {
    READY {
        @Override
        public void changeStatus(TaskRunning running) {
            running.getInterval().clear();
        }
    },RUNNING {
        @Override
        public void changeStatus(TaskRunning running) {
            running.getInterval().start();
            running.setStartTime(LocalDateTime.now());
        }
    },FINISHED {
        @Override
        public void changeStatus(TaskRunning running) {
            running.setDuration(running.getInterval().interval());
            running.setEndTime(LocalDateTime.now());
        }
    },ERROR {
        @Override
        public void changeStatus(TaskRunning running) {
            running.setDuration(running.getInterval().interval());
            running.setEndTime(LocalDateTime.now());
        }
    };

    /**
     * 执行任务状态时处理对应的方法
     * @param running 运行时对象
     */
    abstract public void changeStatus(TaskRunning running);
}
